package cn.xydpeng.springframework.context;

import cn.xydpeng.springframework.beans.BeansException;
import cn.xydpeng.springframework.beans.factory.config.BeanFactoryPostProcessor;
import cn.xydpeng.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import cn.xydpeng.springframework.lang.Nullable;

import java.io.Closeable;

/**
 * @author xydpeng
 * @version v1.0
 * @date: 2022/10/17
 * @description:
 */
public interface ConfigurableApplicationContext extends ApplicationContext, Closeable {

    void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor);

    /**
     * Load or refresh the persistent representation of the configuration, which
     * might be from Java-based configuration, an XML file, a properties file
     * @throws BeansException
     * @throws IllegalStateException
     */
    void refresh() throws BeansException, IllegalStateException;

    /**
     * 注册ApplicationContext容器关闭钩子函数，会触发调用容器中bean的destroy生命周期方法
     */
    void registerShutdownHook();

    @Override
    void close();

    /**
     * Return the internal bean factory of this application context.
     * @return
     * @throws IllegalStateException
     */
    ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;

    void setParent(@Nullable ApplicationContext parent);

}
